using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Dare.Utilities
{
    public sealed class RegexUtil
    {
        public static Regex WildcardToRegex(string str, bool ignoreCase)
        {
            StringBuilder sb = new StringBuilder(str);
            sb.Replace("\\", "\\\\");
            sb.Replace("^", "\\^");
            sb.Replace("$", "\\$");
            sb.Replace("+", "\\+");
            sb.Replace("{", "\\{");
            sb.Replace("}", "\\}");
            sb.Replace(".", "\\.");
            sb.Replace("[", "\\[");
            sb.Replace("]", "\\]");
            sb.Replace("(", "\\(");
            sb.Replace(")", "\\)");
            sb.Replace("*", ".*");
            sb.Replace("?", ".?");
            sb.Append("$");
            return new Regex(sb.ToString(), RegexOptions.IgnoreCase);
        }
    }
}
